package cn.sunlelin.educationserver.service.Impl;

import cn.sunlelin.educationserver.entity.Lessonsituation;
import cn.sunlelin.educationserver.mapper.LessonsituationMapper;
import cn.sunlelin.educationserver.service.LessonsituationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LessonsituationServiceImpl implements LessonsituationService {
    @Autowired
    private LessonsituationMapper lessonsituationMapper;
    @Override
    public Boolean createLessonsituation(Lessonsituation lessonsituation) {
        if(this.selectLessonsituationByUserAndLesson(lessonsituation)!=null)
            return false;
        lessonsituation.setCreateTime(new Date());
        lessonsituationMapper.createLessonsituation(lessonsituation);
        return true;
    }

    @Override
    public Lessonsituation selectLessonsituationByUserAndLesson(Lessonsituation lessonsituation) {
        return lessonsituationMapper.selectLessonsituationByUserAndLesson(lessonsituation);
    }

    @Override
    public List<Lessonsituation> selectLessonsituationByLessonId(Integer lessonId) {
        return lessonsituationMapper.selectLessonsituationByLessonId(lessonId);
    }

    @Override
    public Boolean deleteLessonsituation(Integer lessonsituationId) {
        Lessonsituation lessonsituation=new Lessonsituation();
        lessonsituation.setLessonsituationId(lessonsituationId);
        lessonsituation.setUpdateTime(new Date());
        lessonsituationMapper.deleteLessonsituation(lessonsituation);
        return true;
    }
}
